<?php

/*
 +-----------------------------------------------------------------------+
 | plugins/sieverules/delete_sieverule.inc                               |
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2008-2009, RoundCube Dev. - Switzerland                 |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
 |	 Provide functionality for user to delete a sieve rule               |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Aleksander Machniak <alec@alec.pl>                            |
 | Modifications by: Philip Weir                                         |
 +-----------------------------------------------------------------------+
 | Requires: plugins/sauserprefs/sieverules_func.inc                     |
 +-----------------------------------------------------------------------+

 $Id: $

*/

require_once('plugins/sieverules/sieverules_func.inc');

sieverules_init();

$result = false;
$ids = get_input_value('_iid', RCUBE_INPUT_GET);
if (is_numeric($ids) && isset($SCRIPT[$ids]) && !$SIEVE_ERROR) {
	if ($SIEVE->script->delete_rule($ids)){
		unset($SCRIPT[$ids]);
		$result = $SIEVE->save();
	}
}

if (!$result)
	$OUTPUT->show_message('filterdeleteerror', 'error');
else
	$OUTPUT->show_message('filterdeleted', 'confirmation');

// send response
if ($OUTPUT->ajax_call) {
	$OUTPUT->send();
	exit;
}

// go to sieverules page
rcmail_overwrite_action('sieverules');

?>